package net.butfly.bus.config;

import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;

import net.butfly.bus.config.bean.FilterBean;
import net.butfly.bus.config.bean.NodeBean;
import net.butfly.bus.config.bean.RouterBean;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Config {
	protected final Logger logger = LoggerFactory.getLogger(this.getClass());
	private String busID;
	private Map<String, NodeBean> nodesMap;
	private RouterBean router;
	private List<FilterBean> filterBeanList;

	public String[] matchNodeId(String tx) {
		if (nodesMap != null) {
			Set<String> nodeIds = new HashSet<String>();
			for (Entry<String, NodeBean> et : nodesMap.entrySet())
				if (et.getValue().matchTx(tx))
					nodeIds.add(et.getValue().getId());
			if (nodeIds.size() > 0)
				return nodeIds.toArray(new String[nodeIds.size()]);
		}
		return new String[0];
	}

	public NodeBean getNodeBean(String nodeId) {
		return nodesMap != null ? nodesMap.get(nodeId) : null;
	}

	public void setFilterBeanList(List<FilterBean> filterBeanList) {
		this.filterBeanList = filterBeanList;
	}

	public void setNodesMap(Map<String, NodeBean> nodesMap) {
		this.nodesMap = nodesMap;
	}

	public List<FilterBean> getFilterBeanList() {
		return filterBeanList;
	}

	public RouterBean getRouterBean() {
		return router;
	}

	public void setRouter(RouterBean router) {
		this.router = router;
	}

	public void setBusID(String busID) {
		this.busID = busID;
	}

	public String getBusID() {
		return busID;
	}
}
